package com.example.qxfw.dzzh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.qxfw.common.entity.PotentialPoints;
import com.example.qxfw.dzzh.mapper.PotentialPointMapper;
import com.example.qxfw.dzzh.service.ZdglService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ZdglServiceImpl implements ZdglService {
    @Autowired
    private PotentialPointMapper potentialPointMapper;

    @Override
    public List<PotentialPoints> selectByTypeAndCountyOfTorrentPotentialPoints(String type, String country) {
        return potentialPointMapper.selectList(new LambdaQueryWrapper<PotentialPoints>()
                .eq(StringUtils.isNotBlank(type) && !type.equals("全部"), PotentialPoints::getDisType, type)
                .eq(StringUtils.isNotBlank(country) && !country.equals("全部"), PotentialPoints::getCountry, country));
    }

    @Override
    public List<String> selectCountry() {
        return potentialPointMapper.selectCountry();
    }

    @Override
    public List<String> selectType() {
        return potentialPointMapper.selectDisType();
    }

    @Override
    public PotentialPoints insertOneDate(PotentialPoints points) {
        int insert = potentialPointMapper.insert(points);
        if (insert > 0) {
            return points;
        } else {
            return null;
        }

    }

    @Override
    public int deleteById(String ppID) {
        return potentialPointMapper.deleteById(ppID);
    }

    @Override
    public PotentialPoints updateById(PotentialPoints points) {
        int update = potentialPointMapper.update(points, new UpdateWrapper<PotentialPoints>()
                .eq("pp_id", points.getPpId()));
        if (update > 0) {
            return points;
        } else {
            return null;
        }
    }


}
